<template>
	<view class="container">
		<view>
			<u-tabs :list="List" :current="current" :scrollable=false lineWidth=50 @change="sectionChange"></u-tabs>
			<card v-for="(item,index) in DataList" :key="index" :data="item" :isUser="isUser" :userInfo="userInfo"
				@upload="upload"></card>
			<u-empty v-show="empty" mode="list" icon="../../static/empty/listNone.png">
			</u-empty>
		</view>
	</view>
</template>

<script>
	import Card from './components/card/index.vue'
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import { findReportlnstallation } from '@/api/applyForInstallation.js'
	export default {
		components: {
			Card
		},
		data() {
			return {
				empty: false, //数据为空
				isUser: false, //用户类别
				params: {
					apply_phone:null,
					pass_flag:'0'
				},
				userInfo: {},
				List: [
					{
						name: '待审核'
					},
					{
						name: '已通过'
					},
					{
						name: '未通过'
					}
				],
				current: 0,
				DataList: []
			}
		},
		async onShow() {
			let that = this
			await uni.getStorage({
				key: 'userInfo',
				success(res) {
					that.userInfo = res.data
					that.params.apply_phone = res.data.phonenumber
				}
			})
			await uni.getStorage({
				key: 'isUser',
				complete(res) {
					that.isUser = res.data.dept_id == '103' ? true : false
				}
			})
			that.sectionChange({
				index: 0
			})
		},
		watch: {
			current: {
				handler(newVal, oldVal) {
					this.current = oldVal
				},
				immediate: true,
				deep: true
			}

		},
		methods: {
			upload(value) {
				// 维修人员接收完成任务的时候都会执行页面刷新
				console.log('页面刷新', value)
				this.sectionChange({
					index: value
				})
			},
			sectionChange(index) {
				this.empty = false
				console.log('index', index)
				// this.DataList = []
				this.$set(this, 'current', index.index)
				// this.current = index.index
				this.params.pass_flag = `${index.index+1}`
				findReportlnstallation(this.params).then(result=>{
					console.log('申报进度',result)
					this.DataList = result.data
					if(result.data.length ==0){
						this.empty = true
					}
				})
				
				
				// 判断是维修人员还是用户
				/*
				if (this.isUser) {
					if (index.index == 0) {
						this.params = {
							addBy: this.userInfo.people_code
						}
						acceptByAddBy(this.params).then(res => {
							console.log('维修人员待接单', res)
							this.DataList = res.data
							// this.DataList.forEach(item=>{
							// 	item.photo = item.photo.split(',')
							// })
							if (res.data.length == 0) {
								this.empty = true
							}

						})
					} else if (index.index == 1) {
						taskingByAddBy(this.params).then(res => {
							console.log('维修人员进行中', res)
							this.DataList = res.data
							if (res.data.length == 0) {
								this.empty = true
							}
						})
					} else {
						successByAddBy(this.params).then(res => {
							console.log('维修人员已完成', res)
							this.DataList = res.data
							if (res.data.length == 0) {
								this.empty = true
							}
						})
					}

				} else {
					// 用户
					if (index.index == 0) {
						// 任务进行中
						this.params = {
							status: 5,
							apply_phone: this.userInfo.people_code
						}
						findTasking(this.params).then(res => {
							console.log('用户进行中', res)
							this.DataList = res.data
							if (res.data.length == 0) {
								this.empty = true
							}


						})
					} else {
						this.params = {
							phone: this.userInfo.people_code
						}
						// 任务已完成
						findTaskSuccess(this.params).then(res => {
							console.log('用户已完成', res)
							this.DataList = res.data
							if (res.data.length == 0) {
								this.empty = true
							}

						})
					}
				}
*/
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		width: 100%;
		min-height: 100vh;
		background: #f4f4f5;
		display: inline-block;
	}
</style>